package lib.self.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import lib.self.AppEx;
import lib.self.adapter.viewholder.ViewHolderEx;

/**
 * description: MultipleAdapterEx
 * author: Steven Xiao
 * date: 2017/3/7
 */
public abstract class MultipleAdapterEx<T, VH extends ViewHolderEx> extends Adapter<VH> {
    protected final String TAG = getClass().getSimpleName();

    private ArrayList<T> mList;
    private LayoutInflater mInflater = null;

    public LayoutInflater getInflater() {
        if (mInflater == null) {
            mInflater = LayoutInflater.from(getContext());
        }
        return mInflater;
    }

    public Context getContext() {
        return AppEx.getContext();
    }

    public void setData(ArrayList<T> list) {
        this.mList = list;
    }

    public abstract VH initViewHolder(ViewGroup parent, int viewType);

    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) {
        return initViewHolder(parent, viewType);
    }

    @Override
    public void onBindViewHolder(VH holder, int position) {

    }

    @Override
    public int getItemCount() {
        return mList.isEmpty() ? 0 : mList.size();
    }

    public View getItemView(ViewGroup parent){
        return getInflater().inflate(getItemViewId(),parent,false);
    }

    public abstract int getItemViewId();

    public T getItem(int position) {
        if (mList == null) {
            return null;
        }
        T t = null;
        t = mList.get(position);
        return t;
    }
}
